<?
	session_start();
    include_once "./src/facebook.php";
    include_once "./Post.php";
	include_once "./crawler.php";
	include_once "./MultiRequest.php";
	include_once "./facebookQuery.php";
	include_once "./SentyPost.php";
	include_once "./SentyPostCreator.php";
	include_once "./ClassificationHandler.php";

	if(isset($_SESSION['facebook_s']))
	{
		$facebook_s = $_SESSION['facebook_s'];
		$facebook = unserialize($facebook_s);
	}

?>

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<head>
<title>Show!!!</title>
</head>
<body>
<h3 align="right">
<a href="/"> Home </a>
</h3>
<h3 align="right">
<a href="/list.php?friends"> Friend List </a>
</h3>

<br /><br />

<? 

//Facebook Authentication
//LOGIN

if($_GET['id'])
{
	//Information about me(user) like name, bday, username, etc...
	$mrX = $_GET['id'];
	
	echo "Begin requestes at ".date("D M j G:i:s T Y")."<br />";
	
	$fbQuery =	new FacebookQuery($facebook);
	$crawler = new Crawler($facebook, $mrX);
	$creator = new Creator();
	$classificationHandler = new ClassificationHandler();
	
	//$fbQuery -> setSince('1322697600');
//	$fbQuery -> setUntil('1320764400');
//	$fbQuery -> setLimit('10');

	$userInfo =  $fbQuery -> myInformations();

	echo "Got all posts at ".date("D M j G:i:s T Y")." ... Starting Crawler!<br />";
    $MrXPosts =  $crawler -> cleanPosts();
	echo "Crawler finished at ".date("D M j G:i:s T Y")."<br />";


	echo "SENTY POST creator started at ".date("D M j G:i:s T Y")."<br />";
	$all_senty_post = $creator -> getSentyPosts($MrXPosts, $mrX);
	echo "SENTY POST creator finished at ".date("D M j G:i:s T Y")."<br />";
	
	echo "CLASSIFICATION started at ".date("D M j G:i:s T Y")."<br />";
	$all_senty_post = $classificationHandler -> classifyAll($all_senty_post);
	echo "CLASSIFICATION finished at ".date("D M j G:i:s T Y")."<br />";
	
	

	//echo '<pre>'.print_r($all_senty_post, true).'</pre>';
	
echo '<pre>'.print_r($all_senty_post, true).'</pre>';
/*		
		?><h3><?
		if($post -> message)
		{
			echo ("MESSAGE:".$post -> message) ;
			// We detect the language of the message
			//$result = $language->detect($post -> message);
			$message = $post -> message;
			echo "<br />The message is in : ";
			echo $language->detect($message);
			
			//We count and remove the smiles from the message
			$result1 =  findSmiles($post -> message);
			
			$text = $result1[0];
			
			// Function to normalize the message 
			if ($language->detect($message) == "english")
			{
				$result = normalize($text, $dict);
			
				echo "<br /> CORRECTED MESSAGE : <br />";
				// We display the ressult 
				foreach ($result as $sentences){
					foreach ($sentences as $words){
						echo $words;
					}
					echo "<br />"; // End of the sentence
				}
			}
		}
		if($post -> story)
			echo ("STORY:".$post -> story) ;
	
		?></h3><br/><?
		?><?
		echo ("ID POST: ".$post -> id).'<br>';
		echo ("TYPE POST: ".$post -> type).'<br>';
		echo ("APPLICATION POST: ".$post -> application).'<br>';
		echo ("CREATION DATE: ".$post -> created_time).'<br>';
		echo ("NUM LIKES:  ".$post -> numLikes) ;
		echo (" AND NUM COMMENTS:  ".$post -> numComments);
		?><br /> TAGS: <?
		for($i = 0 ; $i < count($post-> tags); $i++)
		{
			echo ($post-> tags[$i]['name']."(".$post -> tags[$i]['id']."), ");
		}
		?><br /> LIKES: <?
		for($i = 0 ; $i < count($post-> likes); $i++)
		{
			echo ($post -> likes[$i]['id'].',');
		}
		?><br /> COMMENT : <?
		for($i = 0 ; $i < count($post-> comments); $i++)
		{
			if ($language->detect($post -> comments[$i]['message']) == "english")
			{
				echo ("(".$post -> comments[$i]['from']['id'].") : ".
				$post -> comments[$i]['message']." *;* ");
				
				$result1 =  findSmiles($post -> comments[$i]['message']);
				$text = $result1[0];
				// Function to normalize the message 
				$result = normalize($text, $dict);
				echo "<br /> CORRECTED COMMENT : <br />";
				// We display the ressult 
				foreach ($result as $sentences){
					foreach ($sentences as $words){
						echo $words;
					}
					echo "<br />"; // End of the sentence
				}

//				echo '<pre>'.print_r($result, true).'</pre>';
			}
		}
		
		?><br/><br/><?
	
	*/
	//}
	
	echo "At the end".date("D M j G:i:s T Y")."<br />";
	
}
?>
</body>
</html>